<?php
class Application_Model_DbTable_TopProduct extends Zend_Db_Table
{
    protected $_name = 'top_products';

    
    public function getMaxSort()
    {
        $tableName = $this->_db->quoteIdentifier($this->_name);
        $sql = "
            SELECT MAX(sort_id) 
            FROM $tableName 
        ";
        $maxSortId = $this->_db->fetchOne($sql);
        return $maxSortId;
    }
    
    
    function getTopProducts()
    {
        $sql = "
            SELECT t.*, model, filename, description, name, price
            FROM products AS p, `{$this->_name}` AS t
            WHERE p.id = t.product_id 
            ORDER BY t.sort_id
        ";
        $result = $this->_db->query($sql);
        return $result->fetchAll();
    }
}